<template>
	<view class="class flex" v-if="list">
		<scroll-view scroll-y="true" class="nav">
			<view class="nav_item flex f-y-c f-x-c" @click="navAct = index" :class="{act: index == navAct}"
				v-for="(item,index) in list" :key="index">
				<view class="actLine" v-if="index == navAct"></view>
				<view class="text ellipsis t-c">{{item.name}}</view>
			</view>
		</scroll-view>
		<scroll-view scroll-y="true" class="shop_list">
			<view class="box">
				<view class="shop_item" v-for="(val,key) in list[navAct].sunList" :key="key" @click="classlist(list[navAct].id,val.id)">
					<image :src="oss(val.image)" mode="aspectFill" class="cover"></image>
					<view class="title ellipsis">{{val.name}}</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navAct: 0,
				list: ''
			}
		},
		onLoad() {
			this.getcate()
		},
		methods: {
			classlist(id1,id2){
				uni.$u.route({
					url: 'pages/common/list',
					params: {
						id1:id1,
						id2:id2,
					}
				})
			},
			getcate() {
				uni.$u.http.post('/freecate').then(res => {
					if (res.code == 1) {
						// console.log(res.data)
						this.list = res.data
					}
				}).catch((res) => {
			
				})
			},
		}
	}
</script>

<style lang="scss">
	.class {
		
		.nav,
		.shop_list {
			height: calc(100vh - 90rpx);
			overflow: hidden;
			box-sizing: border-box;
		}

		.nav {
			background: #F5F5F5;
			width: 216rpx;
			.nav_item {
				padding: 40rpx 0;
				font-size: 28rpx;
				font-weight: 400;
				color: #989898;

				.text {
					width: 190rpx;
				}

				.actLine {
					width: 8rpx;
					height: 28rpx;
					background: #FEBF4E;
					border-radius: 4rpx;
					margin-right: 15rpx;
				}

				&.act {
					font-size: 32rpx;
					font-weight: 400;
					color: #343434;
					background: #fff;

					.text {
						width: 160rpx;
					}
				}
			}
		}
		
		.shop_list {
			flex: 1;
			padding: 30rpx 40rpx;
			
			.box{
				display: flex;
				flex-wrap: wrap;
				align-items: center;
			}
			.shop_item {
				margin-right: 46rpx;
				margin-bottom: 46rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				&:nth-child(3n + 3) {
					margin-right: 0rpx;
				}

				.cover {
					width: 120rpx;
					height: 120rpx;
				}
				
				.title {
					width: 120rpx;
					text-align: center;
				}

				font-size: 28rpx;
				font-weight: 400;
				color: #343434;
			}
		}
	}
</style>
